#!/bin/bash

# if docker images | grep "dreamacro/clash"; then
#     echo "Image exists"
# else
#     docker load -i ./dreamacro_clash.tar
# fi

source ./download-config.sh

if [ $? -ne 0 ]; then
    echo "Error downloading config"
    return 9
fi

if docker ps -a | grep -qE "clash" ; then
    echo "Container exists and will be removed"
    docker ps -a | grep "clash" | awk '{print $1}' | xargs docker rm -f
fi

 docker run -d --name clash -p 7890:7890 -p 9090:9090 -v ./config.yaml:/root/.config/clash/config.yaml  -v ./Country.mmdb:/root/.config/clash/Country.mmdb  -v ./ui:/root/.config/clash/ui  dreamacro/clash /clash -d /root/.config/clash -f /root/.config/clash/config.yaml -ext-ui /root/.config/clash/ui  

 source ./start.sh
